package com.infolab.aims.domain.purchase;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;

import com.infolab.aims.common.SpecialMuLineToStringStyle;
import com.infolab.aims.common.bean.AbstractModelBean;
import com.infolab.aims.domain.asset.AssetModel;

@Entity
@Table(name="AMTB_PURCHASEORDER_REPAIR")
public class PurchaseOrderRepair extends AbstractModelBean  {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer purchaseOrderRepairId;
	
	@ManyToOne
	@JoinColumn(name="purchaseOrderId")
	private PurchaseOrder purchaseOrder;
	
	@ManyToOne
	@JoinColumn(name="assetModelId")
	private AssetModel assetModel;
	
	private String serialNo;
	
	private String purchaseOrderRemarks;
	
	private String repairStatus;
	
	private Float unitPrice;
	
	@Transient
	private boolean deleted;

	public Integer getPurchaseOrderRepairId() {
		return purchaseOrderRepairId;
	}

	public void setPurchaseOrderRepairId(Integer purchaseOrderRepairId) {
		this.purchaseOrderRepairId = purchaseOrderRepairId;
	}

	public PurchaseOrder getPurchaseOrder() {
		return purchaseOrder;
	}

	public void setPurchaseOrder(PurchaseOrder purchaseOrder) {
		this.purchaseOrder = purchaseOrder;
	}

	public AssetModel getAssetModel() {
		return assetModel;
	}

	public void setAssetModel(AssetModel assetModel) {
		this.assetModel = assetModel;
	}

	public String getSerialNo() {
		return serialNo;
	}

	public void setSerialNo(String serialNo) {
		this.serialNo = serialNo;
	}

	public String getPurchaseOrderRemarks() {
		return purchaseOrderRemarks;
	}

	public void setPurchaseOrderRemarks(String purchaseOrderRemarks) {
		this.purchaseOrderRemarks = purchaseOrderRemarks;
	}

	public Float getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(Float unitPrice) {
		this.unitPrice = unitPrice;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	public String getRepairStatus() {
		return repairStatus;
	}

	public void setRepairStatus(String repairStatus) {
		this.repairStatus = repairStatus;
	}
	
	public boolean isReceived() {
		return StringUtils.equalsIgnoreCase(REPAIRSTATUS_RECEIVED, repairStatus);
	}
	
	public String getAuditContentHead()
	{
		AssetModel model = assetModel;
		if(assetModel==null){
			model = new AssetModel();
		}
		return new ToStringBuilder(this,SpecialMuLineToStringStyle.SPECIAL_MULINE_STYLE)
			.append("Asset Model", model.getAssetModelCode() + " " + model.getAssetModelName())
			//.append("Unit Price",unitPrice)
			.append("Serial No",serialNo)
			.append("Repair Status",repairStatus)
			.append("Remarks", purchaseOrderRemarks)
			.toString();
	}
	
	public static final String REPAIRSTATUS_SENT="SENT";
	public static final String REPAIRSTATUS_RECEIVED="RECEIVED";
}
